package com.naihe.anderson.sms.util;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class ObjectUtil {
	public static Object copySerializableObj(Object oldObj) {
		Object obj = null;
		try {
			// Write the object out to a byte array
			ByteArrayOutputStream bos = new ByteArrayOutputStream();
			ObjectOutputStream out = new ObjectOutputStream(bos);
			out.writeObject(oldObj);
			out.flush();
			out.close();
			// Retrieve an input stream from the byte array and read

			// a copy of the object back in.
			ByteArrayInputStream bis = new ByteArrayInputStream(
					bos.toByteArray());
			ObjectInputStream in = new ObjectInputStream(bis);
			obj = in.readObject();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException cnfe) {
			cnfe.printStackTrace();
		}

		return obj;

	}
	
	public static String phoneNumberFormat(String number){
		return number.replace(" ", "").replace("-", "").replace("+86", "");
	}
	
	public static String phoneNumberFormatPrefix(String number){
		return number.replace("+86", "").replace("12520", "");
	}
	
	public static boolean phoneNumberIsMobile(String number){
		String numberPhone = phoneNumberFormatPrefix(number);
		return (numberPhone.startsWith("13") || numberPhone.startsWith("18") || numberPhone.startsWith("15"));
	}

}
